// pages/xqmatch/xqmatch.js
const app = getApp();
var ea = require('../../utils/each.js');
var WxParse = require('../../utils/wxParse/wxParse.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    imgs: app.data.imgurl +"record.png",
    redflag:app.data.imgurl +"redq.png",
    worksses:app.data.imgurl +"worksss.png",
    dates:app.data.imgurl +"date.png",
    jiangbei: app.data.imgurl +'jiangbei.png',
    solicitation: app.data.imgurl +"date1.png", //征集
    review: app.data.imgurl +"date2.png",              //评审阶段
    publicity: app.data.imgurl +"date3.png",    //公示
    contact:app.data.imgurl +"contact.png",     //联系 
    strophy: app.data.imgurl +"strophy.png",    //奖杯
    judgesd:app.data.imgurl +"judges.png",      //评委
    indexdd: 0,
    imgtypes: ["比赛详情",  "参赛作品"],
    datesd:[
      { src: app.data.imgurl +"date1.png", title: "征集阶段", date:"2019.01.02-2019.01.30"},
      { src: app.data.imgurl +"date2.png", title: "评审阶段", date: "2019.01.02-2019.01.30" },
      { src: app.data.imgurl +"date3.png", title: "公示阶段", date: "2019.01.02-2019.01.30" }
    ],
    strophys: [
      { title: "第一名", reward: "2000元现金+证书+佳能相机" },
      { title: "第二名", reward: "1000元现金+证书+佳能相机" },
      { title: "第三名", reward: "500元现金+证书+佳能相机" }
    ],
    judges:[
      { src: app.data.imgurl +"judgess.png", name: "张益嘉", reward: "四川艺术学院教授", conten:"中国新闻摄影学会会员，四川省摄影协会会员，央视纪录片特邀摄影师，作品曾被“中国国家地理”，“影像视觉”，“摄影之友”等知名杂志刊登，受邀参与央视大型纪录片“城市里的中国“拍摄，诠释了当代摄影人的真实写照。"},
      { src: app.data.imgurl +"judgess.png", name: "张益嘉", reward: "四川艺术学院教授", conten: "中国新闻摄影学会会员，四川省摄影协会会员，央视纪录片特邀摄影师，作品曾被“中国国家地理”，“影像视觉”，“摄影之友”等知名杂志刊登，受邀参与央视大型纪录片“城市里的中国“拍摄，诠释了当代摄影人的真实写照。" },
      { src: app.data.imgurl +"judgess.png", name: "张益嘉", reward: "四川艺术学院教授", conten: "中国新闻摄影学会会员，四川省摄影协会会员，央视纪录片特邀摄影师，作品曾被“中国国家地理”，“影像视觉”，“摄影之友”等知名杂志刊登，受邀参与央视大型纪录片“城市里的中国“拍摄，诠释了当代摄影人的真实写照。" },
      { src: app.data.imgurl +"judgess.png", name: "张益嘉", reward: "四川艺术学院教授", conten: "中国新闻摄影学会会员，四川省摄影协会会员，央视纪录片特邀摄影师，作品曾被“中国国家地理”，“影像视觉”，“摄影之友”等知名杂志刊登，受邀参与央视大型纪录片“城市里的中国“拍摄，诠释了当代摄影人的真实写照。" }
    ],
    bisaiinfourl: app.data.url + 'sheyingjia/xzuoping1/bisaiinfo',
    pingweilisturl: app.data.url + 'sheyingjia/xpage1/getbisaipinweilist',
    zuopinlisturl: app.data.url + 'sheyingjia/xpage1/zuopinglist',
    bisaiid: '',
    workss: [],
     shuju:{

     },
    
    peingweipage:1,
    zuopinpage:1,
    shangchuan:false

  },


  //点击导航栏
  ssx: function (e) {
    console.log(e)
    var indexdd = e.currentTarget.dataset.index;
    this.setData({
      indexdd: indexdd
    })
  },
  //作品详情

  toworks:function(e){
    console.log(e)
    var id = e.currentTarget.dataset.id;
    // return
   wx.navigateTo({
     url: '/pages/xqworks/xqworks?id='+id,
   })

  },
  tiaozhuan:function(){
    var bisai = this.data.bisaiid;
    // this.setData({ shangchuan:true});
    wx.showActionSheet({
      itemList: ['上传图片作品','上传影视作品'],
      success(res) {
        if (res.tapIndex==1){
          wx.navigateTo({
            url: '/pages/uploadvedio/uploadvedio?bisai=' + bisai,
          })
        }else{
          wx.navigateTo({
            url: '/pages/uploadimg/uploadimg?bisai=' + bisai,
          })
        }
      },
    })

  },
  quxiao:function(){
    this.setData({ shangchuan: false });
  },
  s_img:function(){
    var bisai = this.data.bisaiid;
    wx.navigateTo({
      url: '/pages/uploadimg/uploadimg?bisai='+bisai,
    })

  },
  s_video:function(){
    var bisai = this.data.bisaiid;
    wx.navigateTo({
      url: '/pages/uploadvedio/uploadvedio?bisai=' + bisai,
    })

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var id = options.id;
    var that = this;
    that.setData({ bisaiid:id});
    this.getshuju();

    // // console.log(id);
    // wx.showLoading({
    //   title: '加载中',
    // })
    // wx.request({
    //   url: this.data.bisaiinfourl,
    //   data:{id:id},
    //   method:"POST",
    //   success:function(res){
    //     wx.hideLoading();
    //     var data = res.data;
        
    //     if(data.code==200){
    //       console.log(data.data);
    //       var datesd = that.data.datesd;
    //       var newdatesd = [];
    //       ea.each(datesd,function(i,v){
    //         if(i==0){
    //           v.date = data.data.zhenji;
    //         }else if(i==1){
    //           v.date = data.data.pingshen;
    //         } else if (i == 2) {
    //           v.date = data.data.gongshi;
    //         }
    //         newdatesd.push(v);
    //       })
    //       that.setData({ shuju: data.data, datesd:newdatesd});
    //       if (data.data.pinwei.length<4){
    //         that.setData({ peingweipage:0})
    //       }else{
    //         that.setData({ peingweipage: 2})
    //       }
    //       WxParse.wxParse('content', 'html', data.data.brief, that, 25);
    //       // WxParse.wxParse('contents', 'html', '<p>你好</p>', that, 25);
    //       that.getzuopin();
    //     }else{
    //       wx.showToast({
    //         title: data.msg,
    //         icon:'none'
    //       })
    //     }
    //   }
    // })
  },
  //获取比赛数据
  pingweigengduo:function(){
    var that = this;
    var page = this.data.peingweipage;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      })
      return;
    }
    var id = this.data.shuju.id;
    wx.request({
      url: this.data.pingweilisturl,
      data:{page:page,id:id},
      method:"POST",
      success:function(res){
        var data = res.data;
        // console.log(data);
        if(data.code==200){
          var shuju = that.data.shuju;
          var newshuju = shuju.pinwei;
          if(data.data.length<4){
            that.setData({peingweipage:0});
          }else{
            page = page+1;
            that.setData({ peingweipage: page});
          }
          ea.each(data.data,function(i,v){
            newshuju.push(v);
          })
          shuju.pinwei = newshuju;
          that.setData({shuju:shuju});
        
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none'
          })
        }
      }
    })

  },
  //获取比赛作品
  getzuopin:function(){
    var id = this.data.shuju.id;
    var page = this.data.zuopinpage;
    var that = this;
    if(page==0){
      wx.showToast({
        title: '没有更多了',
        icon:'none'
      })
      return
    }
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: that.data.zuopinlisturl,
      data:{id:id,page:page},
      method:"POST",
      success:function(res){
        wx.hideLoading();
        var data = res.data;
        // console.log(data);
        if(data.code==200){
          if(data.data.length<8){
            that.setData({zuopinpage:0});
          }else{
            page = page+1;
            that.setData({ zuopinpage: page });
          }
          var workss = that.data.workss;
          // var newworkss = [];
          ea.each(data.data,function(i,v){
            workss.push(v);
          })
          that.setData({ workss: workss});
        }else{
          wx.showToast({
            title: data.msg,
            icon:'none'
          })
        }
      }
    })
  },
  getshuju:function(func){
var id = this.data.bisaiid;
var that = this;
    // console.log(id);
    wx.showLoading({
      title: '加载中',
    })
    wx.request({
      url: this.data.bisaiinfourl,
      data: { id: id },
      method: "POST",
      success: function (res) {
        if(func){
          func();
        }
        wx.hideLoading();
        var data = res.data;

        if (data.code == 200) {
          console.log(data.data);
          var datesd = that.data.datesd;
          var newdatesd = [];
          ea.each(datesd, function (i, v) {
            if (i == 0) {
              v.date = data.data.zhenji;
            } else if (i == 1) {
              v.date = data.data.pingshen;
            } else if (i == 2) {
              v.date = data.data.gongshi;
            }
            newdatesd.push(v);
          })
          that.setData({ shuju: data.data, datesd: newdatesd });
          if (data.data.pinwei.length < 4) {
            that.setData({ peingweipage: 0 })
          } else {
            that.setData({ peingweipage: 2 })
          }
          WxParse.wxParse('content', 'html', data.data.brief, that, 25);
          // WxParse.wxParse('contents', 'html', '<p>你好</p>', that, 25);
          that.getzuopin();
        } else {
          wx.showToast({
            title: data.msg,
            icon: 'none'
          })
        }
      }
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },


  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    // this.setData({
    //   workss: [],
    //   shuju: {

    //   },

    //   peingweipage: 1,
    //   zuopinpage: 1,
    //   shangchuan: false
    // });
    this.getshuju(function(){
      wx.stopPullDownRefresh();
    });
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var indexdd = this.data.indexdd;
    if(indexdd==1){
      this.getzuopin();
    }
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})